/*
 * Kinetis porting
 * 
 * Author: Major Lin
 * 
*/

#ifndef __KINETIS_FUNC__H_
#define __KINETIS_FUNC__H_

#include "kinetis_map.h"

#define PSTR
#define stepper_pit_isr LPIT0_IRQHandler

/* board related function */
void grbl_pin_mux();
void sei();
void cli();
void _delay_ms(int);
void _delay_us(int);

void arch_spindle_tpm_init();
uint8_t arch_spindle_tpm_status();
void arch_spindle_tpm_update_pwm();
void arch_stepper_init();
void arch_compare_match_isr_enable();
void arch_compare_match_isr_disable();
void arch_timer_reset();

/* serial related function */
/* function to init serial port */
void arch_serial_init();
/* 
 * function to enable tx empty interrupt 
 * callback function arch_serial_tx_empty_isr
*/
void arch_serial_tx_empty_isr_enable();
void arch_serial_tx_empty_isr_disable();
/* 
 * function to enable rx interrupt 
 * callback function arch_serial_rx_isr
*/
void arch_serial_rx_isr_enable();
void arch_serial_rx_isr_disable();
/* arch serial interrupt isr */
void arch_serial_isr();
/* arch serial write*/
void arch_serial_write_byte(unsigned char);
/* arch serial read*/
unsigned char arch_serial_read_byte();

/* gpio related functions */
/* limit port isr, triggered by limit interrupts */
void arch_limit_port_isr();

/* spindle pwm */
void arch_spindle_tpm_init();

void arch_flash_program(uint32_t address, char *data, uint32_t len);


#endif